# Maintainer: Christian Hesse <mail@eworm.de>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Karol Babioch <karol@babioch.de>

pkgname='yubikey-manager'
epoch=1
pkgver=5.2.1
pkgrel=1
pkgdesc='Python library and command line tool for configuring a YubiKey'
arch=('any')
url='https://developers.yubico.com/yubikey-manager/'
license=('BSD')
depends=('python' 'python-click' 'python-cryptography' 'python-pyopenssl' 'python-pyscard'
         'python-fido2' 'ccid' 'yubikey-personalization' 'python-keyring')
makedepends=('python-build' 'python-installer' 'python-poetry-core')
checkdepends=('python-pytest')
# https://developers.yubico.com/Software_Projects/Software_Signing.html
validpgpkeys=('8D0B4EBA9345254BCEC0E843514F078FF4AB24C3'  # Dag Heyman <dag@yubico.com>
              '57A9DEED4C6D962A923BB691816F3ED99921835E'  # Emil Lundberg (Software Developer) <emil@yubico.com>
              '20EE325B86A81BCBD3E56798F04367096FBA95E8') #  Dain Nilsson <dain@yubico.com>
#source=("https://developers.yubico.com/$pkgname/Releases/yubikey-manager-$pkgver.tar.gz"{,.sig})
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/Yubico/yubikey-manager/releases/download/${pkgver}/yubikey_manager-$pkgver.tar.gz"
	"${pkgname}-${pkgver}.tar.gz.sig::https://github.com/Yubico/yubikey-manager/releases/download/${pkgver}/yubikey_manager-$pkgver.tar.gz.sig")
sha256sums=('35c5aa83ac474fd2434c33267dc0e33d312b3969b108f885e533463af3fbe4e1'
            'SKIP')

build() {
	cd "${pkgname/-/_}-${pkgver}"
	python -m build --wheel --no-isolation
}

# check dependency python-makefun is missing...
# check(){
# 	cd "${pkgname/-/_}-${pkgver}"
# 	python -m unittest discover -vs .
# }

package() {
	cd "${pkgname/-/_}-${pkgver}"
	python -m installer --destdir="$pkgdir" dist/*.whl

	install -D -m0644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"

	install -d "${pkgdir}"/usr/share/{bash-completion/completions,zsh/site-functions}
 	PYTHONPATH="$PYTHONPATH:${pkgdir}/usr/" _YKMAN_COMPLETE=bash_source "${pkgdir}"/usr/bin/ykman > "${pkgdir}"/usr/share/bash-completion/completions/ykman || true
 	PYTHONPATH="$PYTHONPATH:${pkgdir}/usr/" _YKMAN_COMPLETE=zsh_source "${pkgdir}"/usr/bin/ykman > "${pkgdir}"/usr/share/zsh/site-functions/_ykman || true
}
